package com.xps.and.yuntong.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xps.and.yuntong.Data.bean1.OrderDriver;
import com.xps.and.yuntong.Entity.Dizhi;
import com.xps.and.yuntong.R;

import java.util.List;

/**
 * Created by administrator on 2017-12-12.
 */

public class DingDanAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater layoutInflater;
    //        private List<Food> data;
    private List<OrderDriver.ReturnBodyBean.StudentInfoBean> data;
    private OrderDriver.ReturnBodyBean.OrderInfoBean ding_danhao;

    public DingDanAdapter(Context context, OrderDriver.ReturnBodyBean.OrderInfoBean ding_danhao, List data_item) {
        Log.e("111", "====DingDanAdapter");
        this.context = context;
        this.ding_danhao = ding_danhao;
        this.data = data_item;

        layoutInflater = layoutInflater.from(context);
    }

    @Override
    public int getCount() {
//        return data.size();
        return 1;
    }

    @Override
    public Object getItem(int position) {
//        return data.get(position);
        return 1;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = null;
        final ViewHolder viewHolder;

        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.dingdan_item1, null);
            viewHolder = new ViewHolder();

            viewHolder.ll1 = (LinearLayout) convertView.findViewById(R.id.ll1);
            viewHolder.tv_dingdan_hao = (TextView) convertView.findViewById(R.id.tv_dingdan_hao);
            viewHolder.tv_date_day = (TextView) convertView.findViewById(R.id.tv_date_day);
            viewHolder.tv_date_hour = (TextView) convertView.findViewById(R.id.tv_date_hour);
            viewHolder.tv_yijing_jiedan = (TextView) convertView.findViewById(R.id.tv_yijing_jiedan);
            viewHolder.tv_dizhi1 = (TextView) convertView.findViewById(R.id.tv_dizhi1);
            viewHolder.tv_dizhi2 = (TextView) convertView.findViewById(R.id.tv_dizhi2);
            viewHolder.tv_dizhi3 = (TextView) convertView.findViewById(R.id.tv_dizhi3);
            viewHolder.tv_dizhi4 = (TextView) convertView.findViewById(R.id.tv_dizhi4);
            viewHolder.tv_dizhi5 = (TextView) convertView.findViewById(R.id.tv_dizhi5);
            viewHolder.rl_1 = (RelativeLayout) convertView.findViewById(R.id.rl_1);
            viewHolder.rl_2 = (RelativeLayout) convertView.findViewById(R.id.rl_2);
            viewHolder.rl_3 = (RelativeLayout) convertView.findViewById(R.id.rl_3);
            viewHolder.rl_4 = (RelativeLayout) convertView.findViewById(R.id.rl_4);
            viewHolder.rl_5 = (RelativeLayout) convertView.findViewById(R.id.rl_5);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

//
        viewHolder.tv_dingdan_hao.setText(ding_danhao.getOrder_sn() + "");
//        viewHolder.tv_date_day.setText(data.get(position).getDeparture_time()+"");
        viewHolder.tv_date_hour.setText(data.get(position).getDeparture_time() + "");
        if (ding_danhao.getOrder_state().equals("3")) {

            viewHolder.tv_yijing_jiedan.setText(R.string.yi_jiedan);

        } else if (ding_danhao.getOrder_state().equals("5")) {
            viewHolder.tv_yijing_jiedan.setText(R.string.jingxing_zhong);

        }else if (ding_danhao.getOrder_state().equals("6")) {
            viewHolder.tv_yijing_jiedan.setText(R.string.yi_wancheng);

        }


        if (data.size() == 0) {
            viewHolder.ll1.setVisibility(View.GONE);
        } else if (data.size() == 1) {

            viewHolder.rl_2.setVisibility(View.GONE);
            viewHolder.rl_3.setVisibility(View.GONE);
            viewHolder.rl_4.setVisibility(View.GONE);
            viewHolder.tv_dizhi1.setText(ding_danhao.getBegin_address() + "");
            viewHolder.tv_dizhi5.setText(ding_danhao.getEnd_address() + "");

        } else if (data.size() == 2) {
            viewHolder.rl_3.setVisibility(View.GONE);
            viewHolder.rl_4.setVisibility(View.GONE);
            viewHolder.tv_dizhi1.setText(ding_danhao.getBegin_address() + "");
            viewHolder.tv_dizhi2.setText(data.get(position).getBegin_address());
            viewHolder.tv_dizhi5.setText(ding_danhao.getEnd_address() + "");
        } else if (data.size() == 3) {
            viewHolder.rl_4.setVisibility(View.GONE);
            viewHolder.tv_dizhi1.setText(ding_danhao.getBegin_address() + "");
            viewHolder.tv_dizhi2.setText(data.get(1).getBegin_address());
            viewHolder.tv_dizhi3.setText(data.get(2).getBegin_address());
            viewHolder.tv_dizhi5.setText(ding_danhao.getEnd_address() + "");
        } else if (data.size() == 4) {
            viewHolder.tv_dizhi1.setText(ding_danhao.getBegin_address() + "");
            viewHolder.tv_dizhi2.setText(data.get(1).getBegin_address());
            viewHolder.tv_dizhi3.setText(data.get(2).getBegin_address());
            viewHolder.tv_dizhi4.setText(data.get(3).getBegin_address());
            viewHolder.tv_dizhi5.setText(ding_danhao.getEnd_address() + "");
        }


        return convertView;
    }

    public class ViewHolder {
        LinearLayout ll1;
        TextView tv_dingdan_hao;
        TextView tv_date_day;
        TextView tv_date_hour;
        TextView tv_yijing_jiedan;
        TextView tv_dizhi1;
        TextView tv_dizhi2;
        TextView tv_dizhi3;
        TextView tv_dizhi4;
        TextView tv_dizhi5;
        RelativeLayout rl_1;
        RelativeLayout rl_2;
        RelativeLayout rl_3;
        RelativeLayout rl_4;
        RelativeLayout rl_5;
//        ListView lv_dingdan_item;


    }


}